<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/jquery.min.js"></script>
    <link rel="stylesheet" href="css/common.css">
    <script src="js/common.js"></script>
</head>
<body>
<img src="" alt="" class="bg" id="background">
<div class="chooseScroll">
    <div class="border" id="slide">
        <img src="" alt="">
    </div>
</div>
<div class="choose startChoose" id="start">点击抽奖</div>
<div class="choose pauseChoose" id="pause">停止</div>
<div class="choose listButton" id="listButton">中奖名单</div>
<div class="back" onclick="window.location.href='lottery.html'"></div>
<div class="listPage" id="listPage">
    <div class="listPadding" id="listPadding"></div>
</div>
<div class="pause" id="winPage">
    <div class="Winning" id="winning"></div>
    <div class="winTxt">
        <p id="name">姓名</p>
        <p id="deptName">研发部</p>
        <p id="phone">18995462359</p>
    </div>
</div>
<div id="counts" class="counts"></div>
</body>
<script>
    var number = parseInt(getUrlparams("number"));
    var myScroll, speed = 100, saveImgurl = [];
    switch (number) {
        case 5:
            $("#background").css("background", "url(image/chooseZero.png)");
            break;
        case 1:
            $("#background").css("background", "url(image/chooseOne.png)");
            break;
        case 2:
            $("#background").css("background", "url(image/chooseTwo.png)");
            break;
        case 3:
            $("#background").css("background", "url(image/chooseThree.png)");
            break;
        case 4:
            $("#background").css("background", "url(image/chooseFour.png)");
            break;
        default:
            $("#background").css("background", "url(image/chooseOne.png)");
    }
    $(document).ready(function () {
        oldUser();
        lucks();

    })

    function oldUser() {
        var url = basePath + "/wechat/getUserList";
        $.ajax({
            url: url,
            type: 'post',
            data: {},
            dataType: 'json',
            success: function (ajaxData) {
                if (ajaxData.code != 1) { //todo code=1 成功
                    alert(ajaxData.msg);
                } else {
                    var data = ajaxData.data;
                    if (data.length > 0) {
                        for (var i = 0; i < data.length; i++) {
                            var src = data[i].wxImage.replace("/132", "/0");
                            saveImgurl.push(src);
                        }
                        $("#slide>img").attr("src", saveImgurl[0]);
                    }
                }
            }, error: function (ajaxData) {
                alert(ajaxData.msg);
            }
        });
    }

    function luckOne() {
        var url = basePath + "/wechat/draw";
        $.ajax({
            url: url,
            type: 'post',
            data: {
                "prizeStatus": number
            },
            dataType: 'json',
            success: function (ajaxData) {
                if (ajaxData.code != 1) { //todo code=1 成功
                    alert(ajaxData.msg);
                } else {
                    var data = ajaxData.data;
                    var src = data.wxImage.replace("/132", "/0");
                    $("#winning").css("background-image", "url(" + src + ")");
                    $("#slide>img").attr("src", src);
                    $("#name").html(data.name);
                    $("#deptName").html(data.deptName);
                    $("#phone").html(data.phone);
                }
            }, error: function (ajaxData) {
                alert(ajaxData.msg);
            }
        });
    }

    //获取中奖用户列表
    function luckList() {
        var url = basePath + "/wechat/getPrizeUserList";
        $.ajax({
            url: url,
            type: 'post',
            data: {
                "prizeStatus": number
            },
            dataType: 'json',
            success: function (ajaxData) {
                if (ajaxData.code != 1) { //todo code=1 成功
                    alert(ajaxData.msg);
                } else {
                    var data = ajaxData.data;
                    var html='';
                    if(data.length<1) html+='<div class="noOne">暂无中奖用户，请返回抽奖！</div>'
                    for (var i = 0; i < data.length; i++) {
                        html+='<div class="onePerson">';
                        html+='<img src='+data[i].wxImage+' alt="">';
                        html+='<div>'+data[i].name+'</div>';
                        html+='<div>'+data[i].deptName+'</div>';
                        html+='</div>';
                    }

                    $("#listPadding").html(html);
                }
            }, error: function (ajaxData) {
                alert(ajaxData.msg);
            }
        });
    }
    //显示当前等级下 已经中奖的人数
    function lucks() {
        var url = basePath + "/wechat/countDraw";
        $.ajax({
            url: url,
            type: 'post',
            data: {
                "prizeStatus": number
            },
            dataType: 'json',
            success: function (ajaxData) {
                if (ajaxData.code != 1) { //todo code=1 成功
                    alert(ajaxData.msg);
                } else {
                    $("#counts").html("注：当前已中奖人数："+ajaxData.data);
                }
            }, error: function (ajaxData) {
                alert(ajaxData.msg);
            }
        });
    }

    function changeImg() {
        $("#slide>img").attr("src", saveImgurl[Math.floor(Math.random() * saveImgurl.length)]);
    }

    $("#listButton").click(function () {
        luckList();
        $("#listPage").slideToggle();
        var limit=$("#counts").html().substr(10);
        if(limit >20)$("#listPadding").css("overflow-y","scroll");
    })
    $("#winPage").click(function () {
        $("#winPage").slideUp();
    })
    $("#pause").click(function () {
        clearInterval(myScroll);
        luckOne();
        setTimeout(function () {
            $("#winPage").slideDown();
        }, 1500);
        lucks();
    })
    $("#start").click(function () {
        $("#listPage").slideUp();
        myScroll = setInterval(changeImg, speed);
    })
</script>
</html>